class Solution {
public:
    int divide(int dividend, int divisor) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        long long a = dividend;
        long long b = divisor;
        bool sign = (a < 0 && b > 0) || (a > 0 && b < 0);

        if (a < 0) {
            a = -a;
        }
        if (b < 0) {
            b = -b;
        }

        long long ans = 0;
        while (a >= b) {
            int k = 0;
            while (a >= (b << k)) {
                ++k;
            }
            --k;
            a -= (b << k);
            ans += (1L << k);
        }
        return sign ? -ans : ans;

    }
};
